package com.colorlight.cloud.complete.entity.event;

import com.colorlight.cloud.complete.api.CompleteEntityEvent;
import com.colorlight.iot.proto.complete.event.CompleteEvent;
import com.google.protobuf.ByteString;
import com.google.protobuf.InvalidProtocolBufferException;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.util.Objects;

/**
 * 保存多功能卡设置进度上报事件
 */
@Data
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Slf4j
public class SaveFunctionSettingUpload implements CompleteEntityEvent {

    /**
     * 保存进度 isFinish = true时为100
     */
    private Integer percent;

    /**
     * 是否保存成功
     */
    private Boolean success;

    @Override
    public SaveFunctionSettingUpload byteConvertObject(ByteString bytes) {
        CompleteEvent.SaveFunctionSettingUpload saveFunctionSettingUpload = null;
        try {
            saveFunctionSettingUpload = CompleteEvent.SaveFunctionSettingUpload.parseFrom(bytes);
        } catch (InvalidProtocolBufferException e) {
            log.error("", e);
        }
        Objects.requireNonNull(saveFunctionSettingUpload);
        this.setPercent(saveFunctionSettingUpload.getPercent());
        this.setSuccess(saveFunctionSettingUpload.getSuccess());
        return this;
    }
}

